package at.fhj.itm;
// TODO Add JavaDoc Documentation Comments

/**
 * @author Patrick Gramsl
 * @version 1.0
 */

public class Queue {
	
  /**
   * Here are all variables that are used by more than one class
   */
  
  private int maxSize;

  private long[] queArray;

  private int front;

  private int rear;

  private int nItems;

  /**
   * Constructor for the class Queue
   * 
   * It defines the maximum size, generates the queue, sets the pointer
   *  for the first element on position 0 and the last inserted position
   *  in front of the queue and initializes the nItems variable with 0
   *   
   * @param s used to get the max queue size from another class
   */
  
  public Queue(int s) {
    maxSize = s;
    queArray = new long[maxSize];
    front = 0;
    rear = -1;
    nItems = 0;
  }

  /**
   * This class inserts a new item at the end
   * 
   * It defines the maximum size, generates the queue, rear gets the
   *    position of the last inserted element and increments the item
   *    number
   */
  
  public void insert(long j) {
    if (rear == maxSize - 1) // deal with wraparound
      rear = -1;
    queArray[++rear] = j; // increment rear and insert
    nItems++; 
  }

  /**
   * Removes an item from the list, sets the front on the last removed
   *  item
   * @return the temporary pointer
   */
  
  public long remove() {
    long temp = queArray[front++]; // get value and incr front
    if (front == maxSize) // deal with wraparound
      front = 0;
    nItems--; // one less item
    return temp;
  }

  /**
   * Getter methods
   * @return
   */
  
  public long peekFront() {
    return queArray[front];
  }

  public boolean isEmpty() {
    return (nItems == 0);
  }

  public boolean isFull() {
    return (nItems == maxSize);
  }

  public int size() {
    return nItems;
  }
}
           
         